import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import * as stackTraceParser from 'stacktrace-parser'

Vue.config.productionTip = false

// 生产环境再去做上传错误处理
if (process.env.NODE_ENV == "production") {
  // 捕获框架内部错误
  Vue.config.errorHandler = function (err, vm, info) {
    const errInfo = stackTraceParser.parse(err.stack)[0]
    const message = err.message
    const lineno = errInfo.lineNumber
    const colno = errInfo.column
    const source = errInfo.file
    axios
      .post("http://127.0.0.1:3000/sendErrorLog", {
        message,
        lineno,
        colno,
        source,
      })
      .then((data) => {
        console.log(data);
      });
  };

  // 捕获js报错
  window.onerror = function (message, source, lineno, colno) {
    axios
      .post("http://127.0.0.1:3000/sendErrorLog", {
        message,
        lineno,
        colno,
        source,
      })
      .then((data) => {
        console.log(data);
      });
  }
}

new Vue({
  render: function (h) { return h(App) },
}).$mount('#app')
